import dog from '@/static/jinbi.jpg'
import runman from '@/static/runman.gif'
import runman1 from '@/static/runman1.png'
import runman2 from '@/static/runman2.png'
import runman3 from '@/static/runman3.png'
import runman4 from '@/static/runman4.png'
import runman5 from '@/static/runman5.png'
import runman6 from '@/static/runman6.png'
import runman7 from '@/static/runman7.png'
import runningback from '@/static/runningback.jpg'
import startbtn from './images/startbtn.jpg'
export default Hilo.Class.create({
    Mixes: Hilo.EventMixin,
    queue: null,  // 下载类
    bg: null,   // 背景
    bigzZongzi: null,   // 大粽子
    zongzi: null,   // 小粽子
    fruit: null,   // 香蕉
    hand: null,   // 手
    beginBtn: null,   // 开始按钮
    score0: null,   // -1分
    score1: null,   // +1分
    score2: null,   // +2分
    runman1: null,   // 开始按钮
    runman2: null,   // -1分
    runman3: null,   // +1分
    runman4: null,   // +2分
    runman5: null,   // -1分
    runman6: null,   // +1分
    runman7: null,   // +2分
    load() {
    
        let imgs = [
            {
            id: 'runman1',
            src: runman1
        },{
            id: 'runman2',
            src: runman2
        },{
            id: 'runman3',
            src: runman3
        },{
            id: 'runman4',
            src: runman5
        },{
            id: 'runman5',
            src: runman5
        },{
            id: 'runman6',
            src: runman6
        },{
            id: 'runman7',
            src: runman7
        },{
            id: 'bg',
            src: runningback
        },
        {
            id: 'bigzZongzi',
            src: dog
        },
        {
            id: 'zongzi',
            src: dog
        },
        {
            id: 'fruit',
            src:dog
        },
        {
            id: 'hand',
            src:runman
        },
        {
            id: 'beginBtn',
            src: startbtn
        },
        {
            id: 'score0',
            src: dog
        },
        {
            id: 'score1',
            src: dog
        },
        {
            id: 'score2',
            src: dog
        }];
        
        this.queue = new Hilo.LoadQueue();
        this.queue.add(imgs);
        this.queue.on('complete', this.onComplete.bind(this));
        this.queue.on('error', this.onError.bind(this));
        this.queue.start();
    },

    onComplete() { //加载完成
        console.log("所有资源加载完成");
        this.bg = this.queue.get('bg').content;
        this.bigzZongzi = this.queue.get('bigzZongzi').content;
        this.zongzi = this.queue.get('zongzi').content;
        this.fruit = this.queue.get('fruit').content;
        this.hand = this.queue.get('hand').content;
        this.beginBtn = this.queue.get('beginBtn').content;
        this.score0 = this.queue.get('score0').content;
        this.score1 = this.queue.get('score1').content;
        this.score2 = this.queue.get('score2').content;
        this.runman1 = this.queue.get('runman1').content;
        this.runman2 = this.queue.get('runman2').content;
        this.runman3 = this.queue.get('runman3').content;
        this.runman4 = this.queue.get('runman4').content;
        this.runman5 = this.queue.get('runman5').content;
        this.runman6 = this.queue.get('runman6').content;
        this.runman7 = this.queue.get('runman7').content;

console.log(this.runman1.width);
        //删除下载队列的complete事件监听
        this.queue.off('complete');
        // complete暴露
        this.fire('complete');
    },

    onError(e) {
        console.error("资源加载错误", e);
    }
});
